package cn.gd.controller.myDesktop.PendingTasks;

import cn.gd.pojo.Approvalinfo;
import cn.gd.pojo.Department;
import cn.gd.service.PendingTasks.impl.PendingTasksServiceImpl;
import cn.gd.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pendingTasks")
@CrossOrigin //设置允许跨域访问
public class PendingTasksController {

    @Autowired
    private PendingTasksServiceImpl service;

    @PostMapping("/queryPendingTasks/{pageNum}/{pageSize}/{status}")
    public Result<Object> queryPendingTasks(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize,
            @PathVariable Integer status,
            @RequestBody(required = false) String... dateRange) {
        System.out.println(pageNum+ ":" + pageSize + ":" + status);
        if (dateRange != null && dateRange.length > 0) {
            System.out.println(dateRange[0] + ":" + dateRange[1]);
        }
        if (status == 1) {
            return Result.ok(service.queryPendingTasks(pageNum, pageSize, dateRange));
        }else if (status == 2) {
            return Result.ok(service.queryTravelApplicationsAll(pageNum, pageSize, dateRange));
        }else if (status == 3) {
            return Result.ok(service.queryVehicleUsageAll(pageNum, pageSize, dateRange));
        }else if (status == 4) {
            return Result.ok(service.querySealUsageAll(pageNum, pageSize, dateRange));
        }else if (status == 5) {
            return Result.ok(service.queryBookborrowingAll(pageNum, pageSize, dateRange));
        }else if (status == 6) {
            return Result.ok(service.queryBusinesscardprintingAll(pageNum, pageSize, dateRange));
        }else if (status == 7) {
            return Result.ok(service.queryIncomeProofApplicationsAll(pageNum, pageSize, dateRange));
        }
        return Result.error();
    }

    @GetMapping("/queryPendingTasksById/{id}/{status}")
    public Result<Object> queryPendingTasksById(
            @PathVariable Integer id,
            @PathVariable Integer status
    ) {
        if (status == 1) {
            return Result.ok(service.queryPendingTasksById1(id));
        }else if (status == 2) {
            return Result.ok(service.queryTravelApplicationsById(id));
        }else if (status == 3) {
            return Result.ok(service.queryVehicleUsageById(id));
        }else if (status == 4) {
            return Result.ok(service.querySealUsageById(id));
        }else if (status == 5) {
            return Result.ok(service.queryBookborrowingById(id));
        }else if (status == 6) {
            return Result.ok(service.queryBusinesscardprintingById(id));
        }else if (status == 7) {
            return Result.ok(service.queryIncomeProofApplicationsById(id));
        }
        return Result.error();
    }

    @PutMapping(value = "/updatePendingTasksById")
    public Result<Boolean> updatePendingTasksById(
            Integer  id,Integer status,
            @RequestBody Approvalinfo approvalinfo
    ){
        if (status == 1) {
            return Result.ok(service.updatePendingTasksById(id, approvalinfo));
        }else if (status == 2) {
            return Result.ok(service.updateTravelApplicationsById(id, approvalinfo));
        }else if (status == 3) {
            return Result.ok(service.updateVehicleUsageById(id, approvalinfo));
        }else if (status == 4) {
            return Result.ok(service.updateSealUsageById(id, approvalinfo));
        }else if (status == 5) {
            return Result.ok(service.updateBookborrowingById(id, approvalinfo));
        }else if (status == 6) {
            return Result.ok(service.updateBusinesscardprintingById(id, approvalinfo));
        }else if (status == 7) {
            return Result.ok(service.updateIncomeProofApplicationsById(id, approvalinfo));
        }
        return Result.error();
    }

    @GetMapping("/getLeadershipAll")
    public Result<List<Department>> getUsersLeadershipAll(@RequestParam Integer userID) {
        return Result.ok(service.getUsersLeadershipAll(userID));
    }
}
